//
//  ZLExamResultCell.m
//  ZLExamination
//
//  Created by Zheng on 2017/8/21.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExamResultCell.h"

#import "ZLExamResultModel.h"

@implementation ZLExamResultCell

- (void)setModels:(NSArray *)models {
    _models = models;
    
    [_models enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        ZLExamResultListModel *model = (ZLExamResultListModel *)obj;
        
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        CGFloat a = idx/5.;
        NSInteger b = idx/5+1;
        NSInteger row = a>b? b: b-1;
        
        bgView.frame = CGRectMake(kSCREEN_WIDTH/5*(idx%5), kSCREEN_WIDTH/5*row, kSCREEN_WIDTH/5, kSCREEN_WIDTH/5);
        [self.contentView addSubview:bgView];
        
        ZLExamResultCellResultTypeStyle style = ZLExamResultCellResultTypeStyleTrue;
        if (model.typeOfAnswer.integerValue == 1) {
            style = ZLExamResultCellResultTypeStyleNull;
        } else if (model.typeOfAnswer.integerValue == 2) {
            style = ZLExamResultCellResultTypeStyleTrue;
        } else {
            style = ZLExamResultCellResultTypeStyleFalse;
        }

        
        UILabel *numberLbl = [self getNumberLblWithStyle:style];
        numberLbl.text = [NSString stringWithFormat:@"%ld",model.questionNumber];
        [bgView addSubview:numberLbl];
        
        [numberLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(bgView);
            make.width.height.mas_equalTo(35);
        }];
    }];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}


- (UILabel *)getNumberLblWithStyle:(ZLExamResultCellResultTypeStyle)style {
    UILabel *numberLbl = [[UILabel alloc] init];
    numberLbl.textAlignment = NSTextAlignmentCenter;
    numberLbl.layer.cornerRadius = 17.5;
    numberLbl.layer.masksToBounds = YES;
    switch (style) {
        case ZLExamResultCellResultTypeStyleTrue: {
            numberLbl.layer.backgroundColor = [kRGB_COLOR(237, 40, 46, 1) CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
            
        case ZLExamResultCellResultTypeStyleFalse: {
            numberLbl.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
            
        case ZLExamResultCellResultTypeStyleNull: {
//            numberLbl.layer.backgroundColor = [[UIColor whiteColor] CGColor];
//            numberLbl.textColor = kMY_BLUE_COLOR;
//            numberLbl.layer.borderColor = [kMY_BLUE_COLOR CGColor];
//            numberLbl.layer.borderWidth = 0.5;
            numberLbl.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
    }
    return numberLbl;
}


@end
